package eg9_7;

import javax.swing.*;
import java.awt.*;
import static javax.swing.SpringLayout.*;
public class SpringLayoutFrame extends JFrame {
    private SpringLayout springLayout;
    public SpringLayoutFrame(){
        springLayout =new SpringLayout();
        Container con =getContentPane();  //获得窗体容器对象
        this.setLayout(springLayout);     //设置窗体布局格式为弹簧式布局

        JLabel toLabel = new JLabel("主题：");
        this.add(toLabel);
        springLayout.putConstraint(NORTH,toLabel,50,NORTH,con);//主题标签北侧-->容器北侧
        springLayout.putConstraint(WEST,toLabel,50,WEST,con);//主题标签南侧-->容器南侧
        JTextField textField =new JTextField();
        this.add(textField);
        springLayout.putConstraint(NORTH,textField,50,NORTH,con);/*主题文本框北侧-->容器北侧*/
        springLayout.putConstraint(WEST,textField,50,EAST,con);/*主题文本框西侧-->容器东侧*/
        springLayout.putConstraint(EAST,textField,-50,EAST,con);/*主题文本框东侧-->容器东侧*/

        JLabel buttonLabel = new JLabel("内容：");
        this.add(buttonLabel);
        springLayout.putConstraint(NORTH,buttonLabel,50,SOUTH,textField); /*内容标签北侧（参考文本框是因为文本框高）-->主题文本框南侧*/
        springLayout.putConstraint(WEST,buttonLabel,50,WEST,con); /*内容标签西侧-->容器西侧*/

        JScrollPane scrollPane = new JScrollPane();

    }
}
